package com.morgan.storageperlib.saf

import android.content.Intent
import android.net.Uri
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import com.morgan.storageperlib.saf.handler.OpenFileHandler
import java.io.InputStream

/**
 *description：读取文件
 *<br>author：caowugao
 *<br>time：2021/3/8 0008 15:49
 */
open class ReadFileHandler(act : AppCompatActivity, contract : ActivityResultContract<Intent, ActivityResult> = ActivityResultContracts.StartActivityForResult(), callback : (Boolean, Uri?, InputStream?) -> Unit) : OpenFileHandler(act, contract, { uri ->

    try {
        val input = act.contentResolver.openInputStream(uri)
        callback.invoke(true, uri, input)
    } catch (e : Throwable) {
        e.printStackTrace()
        callback.invoke(false, null, null)
    }
}){

}